<template>
  <el-dialog title="修改用户" :visible.sync="visible" @close="onClose">
    <el-form :model="formData" ref="form">
      <el-form-item label="用户ID" :label-width="formLabelWidth" readonly>
        <el-input v-model="formData.userId" autocomplete="off"></el-input>
      </el-form-item>

<!--      <el-form-item label="部门ID" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.deptId" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

      <el-form-item label="用户账号" :label-width="formLabelWidth" required>
        <el-input v-model="formData.userName" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="用户昵称" :label-width="formLabelWidth" required>
        <el-input v-model="formData.nickName" autocomplete="off"></el-input>
      </el-form-item>

<!--      <el-form-item label="用户类型" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.userType" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

      <el-form-item label="用户邮箱" :label-width="formLabelWidth" >
        <el-input v-model="formData.email" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="手机号码" :label-width="formLabelWidth" >
        <el-input v-model="formData.phonenumber" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="用户性别" :label-width="formLabelWidth" >
        <el-input v-model="formData.sex" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="角色" :label-width="formLabelWidth" >
        <el-select v-model="formData.roleIds" multiple placeholder="请选择" style="width: 100%">
          <el-option
              v-for="item in roleOptions"
              :key="item.roleId"
              :label="item.roleName"
              :value="item.roleId"
              :disabled="item.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>

<!--      <el-form-item label="头像地址" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.avatar" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

      <el-form-item label="密码" :label-width="formLabelWidth" >
        <el-input v-model="formData.password" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="帐号状态" :label-width="formLabelWidth" >
        <el-input v-model="formData.status" autocomplete="off"></el-input>
      </el-form-item>

<!--      <el-form-item label="删除标志" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.delFlag" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="最后登录IP" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.loginIp" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="最后登录时间" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.loginDate" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="创建者" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.createBy" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="创建时间" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.createTime" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="更新者" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.updateBy" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="更新时间" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.updateTime" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

      <el-form-item label="备注" :label-width="formLabelWidth" >
        <el-input v-model="formData.remark" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="QQ" :label-width="formLabelWidth" >
        <el-input v-model="formData.qq" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="微信" :label-width="formLabelWidth" >
        <el-input v-model="formData.wx" autocomplete="off"></el-input>
      </el-form-item>

<!--      <el-form-item label="身份证号" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.idCard" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="钉钉ID" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.dingId" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="钉钉UnionId" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.dingUnionId" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="微信OpenId" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.wxOpenId" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="微信UnionId" :label-width="formLabelWidth" >-->
<!--        <el-input v-model="formData.wxUnionId" autocomplete="off"></el-input>-->
<!--      </el-form-item>-->

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="onClose">取 消</el-button>
      <el-button type="primary" @click="onSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {updateSysUser, getOneSysUser} from "@/api/sys/user";
import {getSysRoleList} from "@/api/sys/role";

export default {
  name: 'SysUserUpdate',
  props: {
    visible: false,
  },
  data() {
    return {
      formData: {
        userId: 0,
        userName: '',
        nickName: '',
        password: '',
      },
      formLabelWidth: '120px',
      roleOptions:[]
    };
  },
  methods: {
    loadData(id) {
      if (id > 0) {
        getOneSysUser(id).then(res => this.formData = res);
        getSysRoleList().then(res=>{this.roleOptions=res})
      }
    },
    onSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 执行表单提交操作
          // this.formData 包含了通过校验的表单数据
          updateSysUser(this.formData).then(res => this.$emit('submit-success'));
          this.onClose()
        } else {
          console.log('Form validation failed');
        }
      });
    },
    onClose() {
      this.$emit('update:visible', false)
    },
  }
}
</script>

<style>
</style>
